package com.chris.homecare.components
{
	import com.chris.homecare.AppScreen;
	import com.chris.homecare.components.renderers.DrawerMenuListRenderer;
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Label;
	import feathers.controls.LayoutGroup;
	import feathers.controls.List;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.data.ListCollection;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	public class LeftDrawer extends LayoutGroup
	{
		private var backgroundQuad:Quad;
		public var menu:List;

		private var menuHeading:Label;
		public function LeftDrawer()
		{
			super();
		}
		
		override protected function initialize():void
		{
			backgroundQuad = new Quad(1,1,0x000000);
			addChild(backgroundQuad);
			
			menuHeading = new Label();
			menuHeading.nameList.add("grouplist-head-label");
			menuHeading.text = "Menu";
			menuHeading.y = 40*CommonUtils.scaleValue;
			addChild(menuHeading);
			
			menu = new List();
			menu.itemRendererFactory = function():IListItemRenderer
			{
				var renderer:DrawerMenuListRenderer = new DrawerMenuListRenderer();
				return renderer;
			};
			
			menu.dataProvider = new ListCollection(
				[
					{label: "Business", screen: "Business"},
					{label: "Services", screen: "Services"},
					{label: "Team", screen: "Team"},
					{label: "Events", screen: "Event"},
					{label: "Updates", screen: "UpdatesList"},
					{label: "Location", screen: "Location"},
					{label: "Jobs", screen: "JobList"},
					{label: "Request", screen: "Request"},
				]);
			menu.selectedIndex = 0;
			menu.addEventListener(Event.CHANGE, onMenuClicked);
			menu.y = 118*CommonUtils.scaleValue;
			addChild(menu);
		}
		
		private function onMenuClicked():void
		{
			AppScreen(this.parent).menuEventHandler();
		}
		
		override protected function draw():void
		{
			this.backgroundQuad.width = this.menu.width = this.menuHeading.width = this.width;
			this.backgroundQuad.height = this.height;
		}
	}
}